(DEFUN c:layoffall ( / allay_list steplayer steplayobj x)
  (setq allay_list (list (CDR (ASSOC 2 (TBLNEXT "LAYER" T)))))
  (while (setq steplayer (tblnext "layer"))(setq allay_list (append allay_list (list (CDR (ASSOC 2 steplayer))))))
  (mapcar '(lambda (x) (setq steplayobj (entget (tblobjname "layer" x)))(setq steplayobj (subst (cons 62 (- (abs (cdr (assoc 62 steplayobj)))))(assoc 62 steplayobj)steplayobj))(entmod steplayobj)) allay_list)
  (princ)
)
(DEFUN c:layonall ( / allay_list steplayer steplayobj x)
  (setq allay_list (list (CDR (ASSOC 2 (TBLNEXT "LAYER" T)))))
  (while (setq steplayer (tblnext "layer"))(setq allay_list (append allay_list (list (CDR (ASSOC 2 steplayer))))))
  (mapcar '(lambda (x) (setq steplayobj (entget (tblobjname "layer" x)))(setq steplayobj (subst (cons 62 (abs (cdr (assoc 62 steplayobj))))(assoc 62 steplayobj)steplayobj))(entmod steplayobj)) allay_list)
  (princ)
)
(DEFUN layofflist (laylist / steplayobj x);laylist must be a list of layer entity definitions as returned by (TBLOBJNAME <layer entity name>)
  (mapcar '(lambda (x) (setq steplayobj (entget (tblobjname "layer" x)))(setq steplayobj (subst (cons 62 (- (abs (cdr (assoc 62 steplayobj)))))(assoc 62 steplayobj)steplayobj))(entmod steplayobj)) laylist)
  (princ)
)
(DEFUN layonlist (laylist / steplayobj x);laylist must be a list of layer entity definitions as returned by (TBLOBJNAME <layer entity name>)
  (mapcar '(lambda (x) (setq steplayobj (entget (tblobjname "layer" x)))(setq steplayobj (subst (cons 62 (abs (cdr (assoc 62 steplayobj))))(assoc 62 steplayobj)steplayobj))(entmod steplayobj)) laylist)
  (princ)
)
(DEFUN c:laythawall ( / orig_regenmode allay_list steplayer steplayobj x)
  (setq orig_regenmode (GETVAR "REGENMODE"))
  (SETVAR "REGENMODE" 0)
  (setq allay_list (list (CDR (ASSOC 2 (TBLNEXT "LAYER" T)))))
  (while (setq steplayer (tblnext "layer"))(setq allay_list (append allay_list (list (CDR (ASSOC 2 steplayer))))))
  (mapcar '(lambda (x) (setq steplayobj (entget (tblobjname "layer" x)))
             (IF (= 1 (BOOLE 1 1 (CDR (ASSOC 70 steplayobj))))
               (progn
                 (setq steplayobj (subst (cons 70 (1- (cdr (assoc 70 steplayobj))))(assoc 70 steplayobj)steplayobj))
                 (entmod steplayobj)
               )
             )
           )
           allay_list
  )
  (VL-LOAD-COM)
  (VLA-REGEN (VLA-GET-ACTIVEDOCUMENT (VLAX-GET-ACAD-OBJECT)) ACALLVIEWPORTS)
  (SETVAR "REGENMODE" orig_regenmode)
  (princ)
)
(DEFUN c:layfreezeall ( / allay_list steplayer steplayobj x)
  (setq allay_list (list (CDR (ASSOC 2 (TBLNEXT "LAYER" T)))))
  (while (setq steplayer (tblnext "layer"))(setq allay_list (append allay_list (list (CDR (ASSOC 2 steplayer))))))
  (mapcar '(lambda (x) (setq steplayobj (entget (tblobjname "layer" x)))
             (IF (= 1 (BOOLE 1 1 (CDR (ASSOC 70 steplayobj))))
               NIL
               (progn
                 (setq steplayobj (subst (cons 70 (1+ (cdr (assoc 70 steplayobj))))(assoc 70 steplayobj)steplayobj))
                 (entmod steplayobj)
               )
             )
           )
           allay_list
  )
  (princ)
)